19 Glide 可复用的源码

项目地址:https://github.com/bumptech/glide
官方文档:http://bumptech.github.io/glide/
中文文档:https://muyangmin.github.io/glide-docs-cn/
参考链接:https://blog.csdn.net/guolin_blog/article/details/53939176
·
文章目录:
Glide 详解
Glide 源码分析执行流程

参数检查

源码:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package xian.xiao.tao.util;
import android.text.TextUtils;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import java.util.Collection;
/**
* Contains common assertions.
*/
public final class Preconditions {
private Preconditions() {
// Utility class.
}
public static void checkArgument(boolean expression, @NonNull String message) {
if (!expression) {
throw new IllegalArgumentException(message);
}
}
@NonNull
public static <T> T checkNotNull(@Nullable T arg) {
return checkNotNull(arg, "Argument must not be null");
}
@NonNull
public static <T> T checkNotNull(@Nullable T arg, @NonNull String message) {
if (arg == null) {
throw new NullPointerException(message);
}
return arg;
}
@NonNull
public static String checkNotEmpty(@Nullable String string) {
if (TextUtils.isEmpty(string)) {
throw new IllegalArgumentException("Must not be null or empty");
}
return string;
}
@NonNull
public static <T extends Collection<Y>, Y> T checkNotEmpty(@NonNull T collection) {
if (collection.isEmpty()) {
throw new IllegalArgumentException("Must not be empty.");
}
return collection;
}
}

使用:

1
2
3
4
5
Preconditions.checkNotNull(
context,
"You cannot start a load on a not yet attached View or a Fragment where getActivity() "
+ "returns null (which usually occurs when getActivity() is called before the Fragment "
+ "is attached or after the Fragment is destroyed).");